#include "ipsetting.h"
#include "ui_ipsetting.h"
#include "common/common.h"
#include <QRegExp>

IpSetting::IpSetting(QWidget *parent) :
    BaseEditor(QModelIndex(),parent),
    ui(new Ui::IpSetting)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
    setGeometry(WINDOW_GEOMETRY_SHIFT(0.4,0.4,0));
    //QRegExp  setipRegExp("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[//.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])");
    //ui->le_ip->setValidator(new QRegExpValidator(setipRegExp,ui->le_ip));
    ui->le_ip->setInputMask("000.000.000.000");
    ui->le_mask->setInputMask("000.000.000.000");
    ui->le_gateway->setInputMask("000.000.000.000");
    QString ip,mask,gateway;
    platform_sys_info_c::get_sys_ip_addr(ip,mask,gateway);
    ui->le_ip->setText(ip);
    ui->le_mask->setText(mask);
    ui->le_gateway->setText(gateway);
}

IpSetting::~IpSetting()
{
    delete ui;
}

void IpSetting::on_btn_cancel_clicked()
{
    this->reject();
}

void IpSetting::on_btn_ok_clicked()
{
    QString ip,mask,gateway;
    ip = ui->le_ip->text();
    mask = ui->le_mask->text();
    gateway = ui->le_gateway->text();
    platform_sys_info_c::set_sys_ip_addr(ip,mask,gateway);
    emit ipChanged("IP  :"+ip+"\nMask:"+mask+"\n网关:"+gateway);
    this->accept();
}
